using System;
using System.Collections.Generic;
using ProtoModels;
using UnityEngine;

public class TrainingConfig : ScriptableObject
{
	[Serializable]
	public class StatUpdateInfo
	{
		public TrainingType trainingType;

		public PlayerStatsManager.AttributeType attrType;

		public PlayerStatsManager.SkillType skillType;

		public float boost;

		public float multiplier
		{
			get
			{
				PlayerInventory instance = PlayerInventory.instance;
				if (instance.isOwned(PlayerInventory.Item.Trainer))
				{
					return 2f;
				}
				return 1f;
			}
		}

		public float totalBoost
		{
			get
			{
				return boost * multiplier;
			}
		}

		public string GetStatName()
		{
			if (trainingType == TrainingType.Attribute)
			{
				return attrType.ToString();
			}
			return skillType.ToString();
		}
	}

	[Serializable]
	public class Training
	{
		[Serializable]
		public class AttributePrerequisite
		{
			public PlayerStatsManager.AttributeType attrType;

			public int attrVal;
		}

		public static int trainingInt;

		public string trainingName;

		public string text;

		public int levelRequired;

		public int price;

		public CurrencyType currencyType;

		public int durationInMinutes;

		public float energyCost = 10f;

		public List<AttributePrerequisite> attrPrerequisites = new List<AttributePrerequisite>();

		public List<StatUpdateInfo> statUpdateInfo = new List<StatUpdateInfo>();

		public List<TrainingGameDefinitionId> availableTrainings = new List<TrainingGameDefinitionId>();

		public float maxMultiplier
		{
			get
			{
				float num = 1f;
				foreach (StatUpdateInfo item in statUpdateInfo)
				{
					num = Mathf.Max(item.multiplier, num);
				}
				return num;
			}
		}

		public TimeSpan GetTrainingDuration()
		{
			return new TimeSpan(0, durationInMinutes, 0);
		}

		public TrainingGameDefinition GetTrainingGameDefinition()
		{
			string name = string.Empty;
			if (availableTrainings.Count > 0)
			{
				name = availableTrainings[trainingInt % availableTrainings.Count].gameDefinitionName;
				trainingInt++;
			}
			return instance.GetTrainingGameDefinition(name);
		}

		public int GetAttrPrereq(PlayerStatsManager.AttributeType attrType)
		{
			foreach (AttributePrerequisite attrPrerequisite in attrPrerequisites)
			{
				if (attrType == attrPrerequisite.attrType)
				{
					return attrPrerequisite.attrVal;
				}
			}
			return 0;
		}
	}

	[Serializable]
	public class TrainingGameDefinitionId
	{
		public string gameDefinitionName;
	}

	[Serializable]
	public class TrainingGameDefinition
	{
		public string name;

		public string title;

		public string description;

		public PlayerCareerStageDefinition.GameParameters gameParameters;
	}

	private static TrainingConfig instance_;

	public List<Training> skillTrainings = new List<Training>();

	public List<Training> attributeTrainings = new List<Training>();

	public List<TrainingGameDefinition> trainingGameDefinitions = new List<TrainingGameDefinition>();

	public static TrainingConfig instance
	{
		get
		{
			if (instance_ == null)
			{
				instance_ = Resources.Load("TrainingConfig", typeof(TrainingConfig)) as TrainingConfig;
			}
			return instance_;
		}
	}

	public List<Training> GetTrainingsForSkill(PlayerStatsManager.SkillType skillType)
	{
		List<Training> list = new List<Training>();
		foreach (Training skillTraining in instance.skillTrainings)
		{
			foreach (StatUpdateInfo item in skillTraining.statUpdateInfo)
			{
				if (item.trainingType == TrainingType.Skill && item.skillType == skillType)
				{
					list.Add(skillTraining);
					break;
				}
			}
		}
		return list;
	}

	public TrainingGameDefinition GetTrainingGameDefinition(string name)
	{
		foreach (TrainingGameDefinition trainingGameDefinition in trainingGameDefinitions)
		{
			if (trainingGameDefinition.name == name)
			{
				return trainingGameDefinition;
			}
		}
		return trainingGameDefinitions[0];
	}
}
